package com.huanbao.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huanbao.base.lang.Result;
import com.huanbao.entity.CheckResult;
import com.huanbao.service.CheckResultService;
import com.huanbao.util.ShiroUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 检查结果表 前端控制器
 * </p>
 *
 * @author zq
 * @since 2021-04-01
 */
@RestController
@RequestMapping("/check-result")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CheckResultController {

    private final CheckResultService resultService;

    @PostMapping("/publish")
    public Result publish(@RequestBody CheckResult checkResult) {
        String username = ShiroUtil.getProfile().getUsername();
        checkResult.setChecker(username);
        boolean save = resultService.save(checkResult);
        return Result.success(save);
    }

    @GetMapping("/getMyResult")
    public Result getMyResult() {
        List<CheckResult> list = resultService.list(new QueryWrapper<CheckResult>()
                .eq("deleted", 0));
        return Result.success(list);
    }

}
